package com.asion.qkan.ui.model;

import com.asion.qkan.api.ServiceApi;
import com.asion.qkan.entry.ReMenBean;
import com.asion.qkan.ui.contract.SheQuReMenContract;
import com.asion.qkan.utils.retrofitCache.SetCacheUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by asion on 16-10-12.
 */

public class SheQuReMenModel implements SheQuReMenContract.Model {
    //http://api.kkmh.com/v1/feeds/feed_lists?uid=23822625&since=0&page_num=1&catalog_type=2
    @Override
    public void getSheQuReMenListDatas(int type, SheQuReMenContract.OnSheQuReMenGetListener onSheQuGetListener) {
        new Retrofit.Builder().baseUrl("http://api.kkmh.com/")
                .client(SetCacheUtils.setCache())
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(ServiceApi.class)
                .getRemenCommend(type)
                .enqueue(new Callback<ReMenBean>() {
                    @Override
                    public void onResponse(Call<ReMenBean> call, Response<ReMenBean> response) {
                        ReMenBean body = response.body();
                        onSheQuGetListener.onSheQuSuccess(body.getData());
                    }

                    @Override
                    public void onFailure(Call<ReMenBean> call, Throwable t) {
                        onSheQuGetListener.onSheQuError(t);
                    }
                });
    }
}
